library(foreign)
library(ggplot2)
library(scales)
rm(list=ls())

#############################################################
# Figure A.2: Relative Frequency of Significant Predictors of 
# Individual-level Vote Choice in Referendums, 1981-2009 
# (Individual-level Data)
#############################################################

data <- read.dta("./vote_choice/votechoice_out.dta")

label_group=data$group_description[data$indi_group_descr==1]
breaks_group=data$id[data$indi_group_descr==1]

label_group_members=data$group_member_descr
breaks_group_members=data$id

data$variable_num <- factor(data$variable_num,
                            labels = label_group)


data$id

ggplot(data, aes(y = id, shape=factor(baseline),x = significant_share)) +
  geom_point(size=3) + 
  facet_grid(variable_num ~ ., scales = "free", space = "free") +
  theme_bw(base_size = 26)  + 
  ylab("") + xlab("Fraction of significant parameters") +
  theme(strip.text.y = element_text(angle=0)) +
  scale_x_continuous(limits = c(-0.05, 1),labels=percent) +
  scale_y_continuous(expand = c(0, 0.2),breaks=breaks_group_members,labels=label_group_members) +
  scale_shape_manual(values=c(16,4),name = "",labels = c("","Baseline"),guide = FALSE) +
  theme(legend.direction = "horizontal", legend.position = "bottom") +
  theme(panel.grid.minor.y =  element_line(colour = "white", size = 0.5,linetype="dotted")) +
  theme(legend.key = element_blank(), strip.background = element_rect(colour="black", fill="grey90" ) ) + 
  theme(panel.spacing = unit(0.8, "lines")) 
  
ggsave(file="FigureA2.pdf",width=14,height=10 )





